package com.study.gank.mvp.presenter

import com.study.gank.mvp.contract.RandomContract
import com.study.gank.mvp.model.RandomModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject

class RandomPresenter @Inject constructor(
    private val mModel: RandomModel,
    private val mView: RandomContract.View
) : BasePresenter(), RandomContract.Presenter {
    override fun getRandom(type: String) {
        addDisposable(
            mModel.getRandom(type).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ res ->
                    if (res.status == 100) {
                        mView.onShowRandom(res.data[0])
                    }
                }, { e -> println("$e") })
        )
    }
}